<template>
	<div class="viewmore-wrap">
		<div class="btn" @click="handleOpenApp">给ta一个大大的拥抱</div>
		<div class="open_app_fail_tips"  v-show="showFailTips" @click="showFailTips = false">
			<div class="tips_main"></div>
		</div>
	</div>
</template>
<script>
const ua = window.navigator.userAgent;
import nativeSchema from '../../../js/tool-native-schema';
export default {
	name: 'y-viewmore',
	props: {
		id: '',
		routerAddr: '',
		passprops: '',
	},
	data() {
		return {
			showFailTips: false,
		}
	},
	methods: {
		handleOpenApp() {
			if (!this.hasClickOnce) {
				this.hasClickOnce = true;
				if (ua.toLowerCase().match(/micromessenger/i) || ua.toLowerCase().match(/WeiBo/i)) {
					this.showFailTips = true;
				} else {
					this.openApp();
				}
			}
			setTimeout(() => {
				this.hasClickOnce = false;
			}, 2000);
		},
		openApp() {
				nativeSchema.loadSchema({
					// 某个schema协议，例如login,
					schema: `/${this.routerAddr}?${this.passprops}=${this.id}`,
					// schema头协议，
					protocal: "lovelorn://react-native",
					// 发起唤醒请求后，会等待loadWaiting时间，超时则跳转到failUrl，默认3000ms
					loadWaiting: 3000,
					// 唤起失败时的跳转链接，默认跳转到应用商店下载页
					failUrl: ua.indexOf('Android') > -1 ? "https://sj.qq.com/myapp/detail.htm?apkName=com.yryz.lovelorn" : 'itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1438503085',
					// failUrl: window.location.href = window.location.origin + '/static/page/download.html'
				});
			},
	}

}
</script>
<style type="text/css" scoped>
	@import "../../../css/var.css";
	.viewmore-wrap {
		position: fixed;
		z-index: 9;
		bottom: 0.5rem;
		left: 50%;
		margin-left: -1.75rem;

		& .btn {
			width: 3.5rem;
			height: 0.71rem;
			line-height: 0.71rem;
			font-size: 0.3rem;
			color: #fff;
			font-weight: 500;
			text-align: center;
			background: url('../assets/viewmore-bg.png') no-repeat;
			background-size: contain;
		}

	}
</style>